var orderCache = require('../../../utils/mr_xu/apply_order_cache.js')
var common = require('../../../utils/mr_xu/common.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    remark: '',
    carImageList: [],
    location: '',
    locationCoords: '',
    destination: '',
    destinationCoords: '',
    business:''
  },
  onLoad() {
   
    
    let business = orderCache.getItem('business')
    console.log(business)
    this.setData({
      business: business
    })
    let that = this
    let updateInfo = orderCache.getUpdateInfo()
    if (updateInfo) {
      that.setData({
        remark: updateInfo.clue,
        carImageList: updateInfo.clueImageLst ? updateInfo.clueImageLst : [],
        location: updateInfo.location,
        locationCoords: updateInfo.locationCoords,
        destination: updateInfo.destination,
        destinationCoords: updateInfo.destinationCoords,
      })
    }
  },
  imagesChange(e) {

    let images = e.detail
    this.setData({
      carImageList: images
    })

  },
  chooseLocation() {
    let that = this
    wx.chooseLocation({
      success: function(res) {
        if (res.errMsg == 'chooseLocation:ok') {
          console.log(res)
          that.setData({
            location: res.address,
            locationCoords: res.longitude + ',' + res.latitude
          })
        }
      },
    })
  },
  chooseDestination() {
    let that = this
    wx.chooseLocation({
      success: function(res) {
        console.log(res)
        if (res.errMsg == 'chooseLocation:ok') {
          that.setData({
            destination: res.address,
            destinationCoords: res.longitude + ',' + res.latitude
          })
        }
      },
    })
  },
  input_remark: function(res) {
    this.setData({
      remark: res.detail.value
    })
  },
  close(e) {
    let index = e.target.dataset.index
    this.data.pic_list.splice(index, 1)
    this.setData({
      pic_list: this.data.pic_list
    })
  },

  // 添加图片
  add_pic() {
    var that = this
    wx.chooseImage({
      success: function(res) {
        console.log(res)

        if (res.errMsg == "chooseImage:ok") {
          that.setData({
            pic_list: res.tempFilePaths
          })
        }
      },
    })
  },
  next: function() {

    let that = this
    common.safeRun(function() {

      orderCache.setItem('clue', that.data.remark)
      orderCache.setItem('clueImageLst', that.data.carImageList)
      orderCache.setItem('location', that.data.location)
      orderCache.setItem('locationCoords', that.data.locationCoords)
      orderCache.setItem('destination', that.data.destination)
      orderCache.setItem('destinationCoords', that.data.destinationCoords)

      wx.navigateTo({
        url: '../step6_commission/commission',
      })
    })


  }


})